package com.pyb.redis.controller;

/**
 * @version 1.0
 * @Author 彭彦彬
 * @Date 2025/3/18 15:38
 * @注释
 */
import com.pyb.redis.pojo.Student;
import com.pyb.redis.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService service;

    @PostMapping
    public void addStudent(@RequestBody Student student) {
        service.saveOrUpdateStudent(student);
    }

    @GetMapping
    public Map<String, Student> getAllStudents() {
        return service.getAllStudents();
    }

    @GetMapping("/{id}")
    public Student getStudentById(@PathVariable String id) {
        return service.getStudentById(id);
    }

    @DeleteMapping("/{id}")
    public void deleteStudent(@PathVariable String id) {
        service.deleteStudent(id);
    }
}
